UserCommentsList.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Link from 'next/link';
  2. import { Heart } from 'lucide-react';
  3. import { formatDate } from '@/lib/utils/format';
  4. import { UserCommentRow, UserProfileDto } from '@/types/account/profile';
  5. type Props = {
  6. list: UserCommentRow[];
  7. author?: UserProfileDto|null;
  8. };
  9. export default function UserCommentsList({ list, author }: Props)
  10. {
  11. if (list.length === 0) {
  12. return <p className="user-profile__empty">작성한 댓글이 없습니다.</p>;
  13. }
  14. const authorDisplay = author?.name || author?.memberSID || null;
  15. const avatarInitial = (authorDisplay?.charAt(0) || '?').toUpperCase();
  16. return (
  17. <ul className="user-profile__list">
  18. {list.map((row) => (
  19. <li key={row.commentID} className="user-profile__list-item">
  20. <Link href={`/post/${row.postID}`} className="user-profile__list-link">
  21. <div className="user-profile__list-body">
  22. {author && (
  23. <header className="user-profile__list-author">
  24. {author.thumb ? (
  25. <img src={author.thumb} alt={authorDisplay ?? ''} className="user-profile__list-author-avatar" />
  26. ) : (
  27. <span className="user-profile__list-author-avatar user-profile__list-author-avatar--fallback">{avatarInitial}</span>
  28. )}
  29. <span className="user-profile__list-author-name">{authorDisplay}</span>
  30. <span className="user-profile__list-author-handle">@{author.memberSID}</span>
  31. <span className="user-profile__list-time">· {formatDate(row.createdAt)}</span>
  32. </header>
  33. )}
  34. <p className="user-profile__list-comment">{stripTags(row.content)}</p>
  35. <div className="user-profile__list-parent">
  36. <span className="user-profile__list-board">{row.boardName}</span>
  37. <span className="user-profile__list-parent-subject">→ {row.postSubject}</span>
  38. </div>
  39. <div className="user-profile__list-stats">
  40. <span className="user-profile__list-stat" title="좋아요">
  41. <Heart size={14} strokeWidth={1.75} />
  42. {row.likes.toLocaleString()}
  43. </span>
  44. </div>
  45. </div>
  46. </Link>
  47. </li>
  48. ))}
  49. </ul>
  50. );
  51. }
  52. function stripTags(html: string): string {
  53. return html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 200);
  54. }